package gateway.feign.fallback;

import common.config.feign.FallbackFactoryUtil;
import common.model.po.SysUser;
import common.model.request.SendEmailRequest;
import common.model.response.base.Result;
import feign.hystrix.FallbackFactory;
import gateway.feign.SystemFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 米泽鹏
 * @since 2022-3-31 下午 10:29
 */
@Component
@Slf4j
public class GatewayFeignFallbackFactory implements FallbackFactory<SystemFeign> {

	@Override
	public SystemFeign create(Throwable throwable) {
		return FallbackFactoryUtil.create(throwable, new SystemFeign() {
			@Override
			public Result<?> sendEmail(SendEmailRequest request) {
				return Result.error(throwable);
			}

			@Override
			public Result<List<SysUser>> getAllUser() {
				return Result.error(throwable);
			}

			@Override
			public Result<SysUser> deleteUserById(Integer id) {
				return Result.error(throwable);
			}

			@Override
			public Result<SysUser> getUserById(Integer id) {
				return Result.error(throwable);
			}

			@Override
			public Result<SysUser> addUser(SysUser user) {
				return Result.error(throwable);
			}
		});
	}

}
